<?php 
	$type=$db->db_query("
		SELECT 
			products_info,products_image, products_fsk18, products_usk 
		FROM ".TABLE_PRODUCTS." 
		WHERE products_id = ".
	$db->db_prepare($_GET['pID']));
	$content='
$(function(){
	if ($("input[name=submit_target]").length > 0) {
		$("input[name=submit_target]").val("cart");
		$(".add_to_wislist").click(function(){
			$("input[name=submit_target]").val("wish_list");
			$("#cart_quantity").submit();
		});
	}
	$(".reviews_write,.reviews_write_cancel").click(function(){
		$("#product_reviews_write, .reviews_write").fadeToggle();
	});
	$(".qty_plus").click(function(e){
		var a=$(".products_qty").val();
		var b=parseInt(a)+parseInt(1);
		$(".products_qty").val(b);
		e.preventDefault();
		var c=$("#cart_quantity").serialize(true);
		xajax_getNewPrice(c);
	});
	$(".qty_minus").click(function(e){
		var a=$(".products_qty").val();
		if(a>1){
			$(".products_qty").val(a-1);
		}
		e.preventDefault();
		var b=$("#cart_quantity").serialize(true);
		xajax_getNewPrice(b);
	});
	$(".products_qty").keyup(function(){
		var qty=$(".products_qty").val();
		if(qty>0 && qty!=""){
			var d=$("#cart_quantity").serialize();
			xajax_getNewPrice(d);
		}
	});
	
	var d=$("#cart_quantity").serialize();
	xajax_getNewPrice(d);
	$(".option").change(function(e){
		e.preventDefault();
		var a=$("#cart_quantity").serialize(true);
		xajax_getNewPrice(a);
	});';
		
	if($type->fields['products_info']=="tabs"){
		$content .= '
$("#product_info_tabs").tabs({
	fx:{opacity:"toggle"},
	show:function(event,ui){
		var tabName=ui.panel.id;
		if(tabName=="also_purchased_tab"||tabName=="reverse_cross_selling_tab"||tabName=="cross_selling_tab"){
			var new_tab=tabName.substring(0,tabName.length-4);
			var a=$("#"+new_tab+" li").tallestSize();
			$("ul#"+new_tab+" li").each(function(){
				$(this).height(a);
			});
		}
	}
}).fadeIn();';
	}
	elseif($type->fields['products_info']=="accordion"){
		$content .= '
$("#products_info_accordion").accordion({
	header:"h3",
	fx:{opacity:"toggle"},
	autoHeight:false
}).fadeIn();';
	}
	
	$content .= '
$(".product_info_tell_a_friend_button").click(function(){
	';
	if($type->fields['products_info']=="tabs"){
		$content .= 
	'$.scrollTo($("#product_info_tabs"),1000);
	$("#product_info_tabs").tabs("select","tell_a_friend");';
	}
	elseif($type->fields['products_info']=="accordion"){
		$content .=
	'$.scrollTo($("#products_info_accordion"),1000);$("#products_info_accordion").accordion("activate","#tell_a_friend");';
	}
	elseif($type->fields['products_info']=="plain"){
		$content .=
	'$.scrollTo($("#tell_a_friend"),1000);';
	}
	$content .='
	return false
});

$(".product_info_reviews_button").click(function(){
	';
	if($type->fields['products_info']=="tabs"){
		$content .=
	'$.scrollTo($("#product_info_tabs"),1000);
	$("#product_info_tabs").tabs("select","reviews");';
	}
	elseif($type->fields['products_info']=="accordion"){
		$content .= 
	'$.scrollTo($("#products_info_accordion"),1000);
	$("#products_info_accordion").accordion("activate","#reviews");';
	}
	elseif($type->fields['products_info']=="plain"){
		$content .= 
	'$.scrollTo($("#reviews"),1000);';
	}
	$content .= '
	return false
});

$(".buy_product").click(function(){
	var a=$(this).parent().parent().attr("id");
	showOverlay(a);
	xajax_addCart(a)
});

$(".product_overlay").mouseout(function(){ $(this).hide() });';

	if(isset($_GET["video"])&&$_GET["video"]=="flash"){
		$content .= '
$(".video").prettyPhoto({deeplinking:false});';
	}

	if(isset($_GET["cpp"])){
		if(!empty($type->fields['products_image'])){
			$img[]=DIR_WS_POPUP_IMAGES.$type->fields['products_image'];
			require_once(DIR_FS_INC.'inc.get_products_mo_images.php');
			$index = '0';
			if($mo_img = get_products_mo_images($_GET['pID'])){
				foreach($mo_img AS $mo){
					$img[] = DIR_WS_POPUP_IMAGES.$mo['image_name'];
					$index="$('ul.ad-thumb-list img').index( $('ul.ad-thumb-list img').filter(function(){return $(this).css('opacity') == 1;}) )";
				}
			}
			$content .= '
var pPimages=[\'/'.implode("','/",$img).'\'];
$.fn.prettyPhoto({allow_resize: false});
$(".ad-image-wrapper").click(function(){
	$.prettyPhoto.open(pPimages,'.$index.');
});';
		}
	}
	
	else{
		$content .='
$(".product_info_zoom").hide();';
	}

	if(SOCIAL_BUTTON=="original"){
		$content .='var socials="<span class=\"left\"><a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-count=\"horizontal\" data-lang=\"de\">Twittern</a><script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script></span><span class=\"left\"><iframe src=\"http://www.facebook.com/plugins/like.php?href="+encodeURI(location.href)+"&amp;layout=button_count&amp;show_faces=false&amp;width=120&amp;action=recommend&amp;font=verdana&amp;colorscheme=light&amp;height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none;overflow:hidden;width:130px;height:21px;\" allowTransparency=\"true\"></iframe></span><span class=\"left\"><script type=\"text/javascript\" src=\"http://apis.google.com/js/plusone.js\"></script><g:plusone size=\"medium\"></g:plusone></span>";$(".social_buttons").html(socials).fadeIn();';
	}
	elseif(SOCIAL_BUTTON == "2click"){
		$content .= '$(".social_buttons").socialSharePrivacy().fadeIn();';
	}
	
	$content .= 'if(document.location.hash!=""){url_id=document.location.hash.substr(1,document.location.hash.length);';
	if($type->fields['products_info']=="tabs"){
		$content .= '$("#product_info_tabs").tabs("select",url_id);';
	}
	elseif($type->fields['products_info']=="accordion"){
		$content .= '$("#products_info_accordion").accordion("activate","#"+url_id);';
	}
	$content .='}$(".callback_open").click(function(){if($(this).is(":checked")){$(".ask_callback").fadeIn()}else{$(".ask_callback").hide()}});$.datepicker.setDefaults($.datepicker.regional[""]);$(".callback_date").datepicker($.datepicker.regional["'.$_GET["lc"].'"]);$(".callback_date").datepicker({minDate: new Date("'.date("Y").'","'.date("m").'","'.date("d").'"),dateFormat:"dd.mm.yy"});$(".ui-datepicker").addClass("shadow")});';
	
	if(isset($_GET["treepodia"])&&$_GET["treepodia"]=="video"){
		$content .= 'var trpdSKU="'.$_GET["pID"].'";var video;var product;function initTreepodia(){product=Treepodia.getProduct("'.TREEPODIA_UUID.'",trpdSKU);product.requestVideo(handleVideo)}function handleVideo(a){video=a;if(a.hasVideos()){';
		if(TREEPODIA_VIDEO_OPTIONS=="overlay"){
			$content .='$("video-btn").show();';
		}
		elseif(TREEPODIA_VIDEO_OPTIONS=="embedded"){
			$content .='a.setPlayOnClick(true);a.show("video-player-location");';
		}
		$content .='}}';
	}